package com.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dao.ClassroomTimeDao;
import com.mybatis.po.ClassroomTime;

@Controller
public class ClassController {
	@Autowired
	public ClassroomTimeDao classroomTimedao;

	@RequestMapping("/returnClassroom")
	@ResponseBody
	public Map<String, List> returnClass(ClassroomTime request) {
		Map<String, List> map = new HashMap<String, List>();
		List<ClassroomTime> listCla;
		List<String> returnlistCla = new ArrayList<String>();
		listCla = classroomTimedao.selectClassroomBySlotTime(request);
		switch (request.getCTimeSlot()) {
		case "上午":
			for (ClassroomTime classroom : listCla) {
				String TimeSlot = classroom.getCTimeSlot();
				String[] array = TimeSlot.split("\\|");
				int i = 0;
				for (String str : array) {
					if (str.equals("12") || str.equals("34")) {
						i++;
					}
				}
				if (i == 0) {
					returnlistCla.add(classroom.getCcode());
				} else {
					i = 0;
				}
			}

			break; // 可选
		case "下午":
			for (ClassroomTime classroom : listCla) {
				String TimeSlot = classroom.getCTimeSlot();
				String[] array = TimeSlot.split("\\|");
				int i = 0;
				for (String str : array) {
					if (str.equals("56") || str.equals("78")) {
						i++;
					}
				}
				if (i == 0) {
					returnlistCla.add(classroom.getCcode());
				} else {
					i = 0;
				}
			}

			break; // 可选

		case "傍晚":
			for (ClassroomTime classroom : listCla) {
				String TimeSlot = classroom.getCTimeSlot();
				String[] array = TimeSlot.split("\\|");
				int i = 0;
				for (String str : array) {
					if (str.equals("910") || str.equals("1112")) {
						i++;
					}
				}
				if (i == 0) {
					returnlistCla.add(classroom.getCcode());
				} else {
					i = 0;
				}
			}

			break; // 可选
		case "白天":
			for (ClassroomTime classroom : listCla) {
				String TimeSlot = classroom.getCTimeSlot();
				String[] array = TimeSlot.split("\\|");
				int i = 0;
				for (String str : array) {
					if (str.equals("12") || str.equals("34") || str.equals("56") || str.equals("78")) {
						i++;
					}
				}
				if (i == 0) {
					returnlistCla.add(classroom.getCcode());
				} else {
					i = 0;
				}
			}

			break; // 可选
		case "整天":
			for (ClassroomTime classroom : listCla) {
				String TimeSlot = classroom.getCTimeSlot();
				String[] array = TimeSlot.split("\\|");
				int i = 0;
				for (String str : array) {
					if (str.equals("12") || str.equals("34") || str.equals("56") || str.equals("78")
							|| str.equals("910") || str.equals("1112")) {
						i++;
					}
				}
				if (i == 0) {
					returnlistCla.add(classroom.getCcode());
				} else {
					i = 0;
				}
			}
			break; // 可选
		default: // 可选
			for (ClassroomTime classroom : listCla) {
				String TimeSlot = classroom.getCTimeSlot();
				String[] array = TimeSlot.split("\\|");
				int i = 0;
				for (String str : array) {
					if (str.equals(request.getCTimeSlot())) {
						i++;
					}
				}
				if (i == 0) {
					returnlistCla.add(classroom.getCcode());
				} else {
					i = 0;
				}
			}
			break; // 可选
		}
		map.put("classroom", returnlistCla);
		return map;
	}
}
